package com.yinhe.music.yhmusic.search;

import com.yinhe.music.yhmusic.base.BaseModel;
import com.yinhe.music.yhmusic.base.BasePresenter;
import com.yinhe.music.yhmusic.network.response.ResponseTransformer;

public class SearchPresenter extends BasePresenter<BaseModel, SearchContract.ISearchView> implements SearchContract.ISearchPresenter {
    @Override
    public void getSearchTips(String keyWords) {
        if (getView() == null) {
            return;
        }

        addSubscription(mModel.getSearchTips(keyWords)
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(briefSearchInfo -> {
                    getView().setSearchTipsUI(briefSearchInfo.getSearchTipsList());
                }, throwable -> {
                    getView().showMessage(throwable);
                }));
    }

    @Override
    public void getHotSearch() {
        if (getView() == null) {
            return;
        }

        addSubscription(mModel.getHotSearch()
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(hotSearchInfo -> {
                    getView().setSearchTipsUI(hotSearchInfo.getHotSearchList());
                }, throwable -> {
                    getView().showMessage(throwable);
                }));
    }
}
